<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class cache extends Admin_Controller {

    public function index(){
        //   exit("aa");

        $p = array();
        if($this->is_postback()){
            $cache_folder = FCPATH."application/cache/";
            if(isset($_POST['del_all'])){
                // echo 'aa';
                delete_files($cache_folder);
            }
            else
            {
                if(isset($_POST['del_entry_index'])){
                    if(file_exists($cache_folder."entry-index.html")){
                        unlink($cache_folder."entry-index.html");
                    }
                }

                if(isset($_POST['del_page'])){
                    // 删除所有单页缓存
                    $files =  get_dir_file_info($cache_folder);
                    foreach($files as $fn=>$f)
                    {
                        $prefix = "page-show-";
                        if(substr($fn,0,strlen($prefix))==$prefix)
                        {
                            unlink($cache_folder.$fn);
                        }
                    }
                }

                if(isset($_POST['del_article_index'])){
                    // 删除所有单页缓存
                    $files =  get_dir_file_info($cache_folder);
                    foreach($files as $fn=>$f)
                    {
                        $prefix = "article-index-";
                        if(substr($fn,0,strlen($prefix))==$prefix)
                        {
                            unlink($cache_folder.$fn);
                        }
                    }
                }


                if(isset($_POST['del_article'])){
                    // 删除所有单页缓存
                    $files =  get_dir_file_info($cache_folder);
                    foreach($files as $fn=>$f)
                    {
                        $prefix = "article-show-";
                        if(substr($fn,0,strlen($prefix))==$prefix)
                        {
                            unlink($cache_folder.$fn);
                        }
                    }
                }
            }

            $p = array('error'=>'success');
        }

        //  print_r($p);exit;
        $this->load->view("admin/v_cache",$p);
    }
	public function execute()
	{
		// echo APPPATH;exit;
		delete_files(APPPATH."cache/");   
		
		$this->load->view("admin/v_delete_cache",array("returnurl"=>urldecode($this->input->get('returnurl'))));
		
	}
}